layui.use(['jquery', 'table', 'util', 'form', 'laydate'], function() {
	var $ = layui.jquery;
	var table = layui.table;
	var util = layui.util;
	var form = layui.form;
	var laydate = layui.laydate;

	table.render({
		elem: '#table',
		url: 'tableData',
		page: true,
		skin: 'line',
		request: {
			pageName: 'current',
			limitName: 'size'
		},
		cols: [[
			{field: 'userId', title: '登录用户', templet: function(d) {
				return '<a href="../user/list?username=' + d.user.username + '">' + d.user.name + '</a>';
			}},
			{field: 'loginTime', title: '登录时间', minWidth: 180, sort: true, templet: function(d) {
				return util.toDateString(d.loginTime);
			}},
			{field: 'host', title: '登录主机'},
			{field: 'os', title: '操作系统'},
			{field: 'ua', title: '浏览器'},
			{field: 'uaVersion', title: '浏览器版本'}
		]],
		autoSort: false,
		initSort: {
			field: 'loginTime',
			type: 'desc'
		},
		where: {
			orderByField: 'loginTime',
			isAsc: false
		}
	});
	table.on('sort', function(obj) {
		table.reload('table', {
			initSort: obj,
			where: {
				orderByField: obj.field,
				isAsc: obj.type ? obj.type == 'asc' : null
			}
		})
	});
	form.on('submit(search)', function(data) {
		table.reload('table', {
			where: data.field,
			page: {
				curr: 1
			}
		});
	});
	laydate.render({
		elem: '[name="loginTime"]',
		type: 'datetime',
		range: true
	});
});